/*
 * @Author: your name
 * @Date: 2022-04-07 10:24:04
 * @LastEditTime: 2022-04-07 10:35:38
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /comic-algorithm/chapter05/5.2.js
 */
/**
|--------------------------------------------------
| 判断链表有环
|--------------------------------------------------
**/
function ListNode(val) {
  this.val = val;
  this.next = null;
}

function isCycle(head) {
  let p1 = head;
  let p2 = head;

  while (p2 != null && p2.next != null) {
    p1 = p1.next;
    p2 = p2.next.next;
    if (p1 == p2) return true;
  }
  return false;
}
